import os
import shutil
import json


#  这个函数,是之前用于分类一个模型不同阶段结果
#  做法是,将一张图片,它的各个阶段,放在一个文件夹中
# 下面是分类115张图片，生成的compare_results文件夹
# 这里有改正
def extractModelsPrimeP(src,models,target,new_models = None):
    "将abs路径下models里面的模型里prime——pics里有的图片全部移动到target"

    # 先读出优势图片
    base_path = "./"
    with open(base_path + "prime_pics.json", "r", encoding="utf8") as f:
        data = json.loads(f.read())

    # 根据自己的较好的模型的模型名,进行操作

    for i,m in enumerate(models):    # 这个是待比较的模型
        print("\n移动",m,end=":")

        modelpics_dir = os.path.join(src,m)   # 模型名路径
        target_modelpics_dir = os.path.join(target,m if not new_models else new_models[i])   # 要转移的模型名路径
        os.makedirs(target_modelpics_dir,exist_ok=True)

        files = os.listdir(modelpics_dir)   # 先读出所有的文件,然后按索引取

        for rIds in data.values():
            for row in rIds:# 行号+1就是图片所在的索引位置
                print(row,end = ' ')
                # 设置源文件和目标文件路径
                file_path = os.path.join(modelpics_dir, files[row - 1])
                new_file_path = os.path.join(target_modelpics_dir, files[row - 1])

                shutil.copyfile(file_path, new_file_path)  # 复制


if __name__ == '__main__':
    # 模型名有哪些？
    models = ["CycleFusion","DDcGAN","DenseFuse","FusionGAN","IFCNN-MEAN","NestFuse_Avg","SeAFusion","ADF","CSR","FPDE","IFEVIP","IVIFBayes","VSMWLS"]
    new_models = ["CycleFusion", "DDcGAN", "DenseFuse", "FusionGAN", "IFCNN_Mean", "NestFuse_Avg", "SeAFusion","ADF", "CSR", "FPDE", "IFEVIP", "Bayes","VSMWLS"]


    # 将源图像，融合的结果图像添加路径就可以直接运行。
    src = r"D:\cycleFusion-project\msrs-113\fullResult"
    target = r"D:\cycleFusion-project\msrs-113\cmpResult"

    extractModelsPrimeP(src,models,target,new_models)

